<?php
/**
 * Created by PhpStorm.
 * User: silov
 * Date: 15/6/24
 * Time: 15:13
 */
namespace Home\Model;

use Think\Cache\Driver\Memcache;
use Think\Model;
class ArticleModel extends Model {
    protected $tableName = "blog_article";

    public static $typeConfig = [
        1   => 'PHPER',
        2   => 'THINK',
        3   => 'GOODLIFE',
        4   => 'ABOUT',
    ];
    /**
     * @var string Api token redis key Pre_Uhash
     */
    const ARTICLE_MEMCACHE_ID_PREFIX = 'article_memcache_id_';

    /**
     * 根据ID获取文章详情
     * @param $id
     * @return mixed
     */
    public function getArticleById($id)
    {
//        $cache = Memcache::getInstance();
//        $key = self::ARTICLE_MEMCACHE_ID_PREFIX . $id;
//        $article = $cache->get($key);
//        if (empty($article)) {
            $article = $this->where(['id' => intval($id)])->find();
//            !empty($article) && $cache->set($key, $article);
//        }
        return $article;
    }

    public function getSiderList($limit = 3)
    {
        $list = $this->where(['status' => 1, 'is_index' => 0, 'type' => ['in',[1,2,3]]])->order(['publish_time' => 'DESC'])->limit($limit)->select();
        foreach ($list as $k=>$v) {
            unset($list[$k]['content']);
        }
        return $list;
    }
}